<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :model="filters" :inline="true">
				<el-form-item>
					<el-input v-model="filters.keywords" placeholder="关键字" ></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getTenants">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" >新增</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="batchDownLoad" :disabled="this.sels.length===0">批量下载</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表v-loading="listLoading"-->
		<el-table :data="tenants" v-loading="listLoading" @selection-change="selsChange" highlight-current-row  style="width: 100%;">
			<!--多选框-->
			<el-table-column type="selection" width="55">
			</el-table-column>
			<!--索引值,为什么不用id,id不序号-->
			<el-table-column type="index" width="60">
			</el-table-column>
			<!--其他都设置值,只有一个不设置值就自动适应了-->
			<el-table-column prop="companyName" label="机构名称">
			</el-table-column>
			<el-table-column prop="companyNum" label="营业执照">
			</el-table-column>
			<el-table-column prop="address" label="公司地址">
			</el-table-column>
			<el-table-column prop="logo" label="LOGO">

			</el-table-column>
			<el-table-column label="操作" width="250">
				<template scope="scope">
					<el-button size="small"  @click="edit(scope.row)">编辑</el-button>
					<el-button type="danger" size="small" @click="del(scope.row)">删除</el-button>
					<!--
					<a class='download' :href='javaScript=void(0)' download=""  title="下载">
						<el-button type="danger" size="small" @click="download(scope.row)">下载图片</el-button>
					</a>-->
					<a class='download' :href='downLoadHttp' download="下载" target="_blank"  title="下载">

						<el-button type="success" size="small" @click="downPhoto(scope.row)">下载图片</el-button>
					</a>
					<!--<a class="bt-green" href="http://118.25.154.214:8888/group1/M00/00/01/dhma1l9aPgeAXPMrAAJYlTtgkLI935.jpg" target="_blank" rel="nofollow">
						下载图片
					</a>-->

				</template>
			</el-table-column>
		</el-table>
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger">批量删除</el-button>
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange"  :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>
	export default {
		data() {
			return {
				downLoadHttp:"",
				sels: [],//列表选中列
                listLoading:false,
				//查询对象
				filters:{
					keywords:''
				},
				page:1,//当前页,要传递到后台的
				total:0, //分页总数
			    tenants:[], //当前页数据
			}
		},
		methods: {
			//下载图片
			downPhoto(row){

				this.downLoadHttp = this.$downUrl + row.logo;
				//路径
				var param = {
					path: row.logo
				};
				this.$http.post("/file/fastdfs/download", param).then((res => {
					if(res.data.success){
						this.$message({
							message: '操作成功!',
							type: 'success'
						});
					}
					else{
						this.$message({
							message: res.data.message,
							type: 'error'
						});
					}

				}));
			},

			//勾选框事件改变
			selsChange: function (sels) {
				//给勾选框设置值，显示批量删除的按钮
				this.sels = sels;
			},
			//批量删除
			batchDownLoad: function () {
				let groups = this.sels.map(item => item.logo);
				this.$http.patch("/file/fastdfs/download", groups).then((res => {
					if(res.data.success){
						this.$message({
							message: '操作成功!',
							type: 'success'
						});

						//
					}
					else{
						this.$message({
							message: res.data.message,
							type: 'error'
						});
					}

				}));
			},
            handleCurrentChange(curentPage){
                this.page = curentPage;
                this.getTenants();
			},
            getTenants(){
                //发送Ajax请求后台获取数据  axios
				//添加分页条件及高级查询条件
				let para = {
				    "page":this.page,
					"keyword":this.filters.keywords
				};
				this.listLoading = true; //显示加载圈
				//分页查询
                this.$http.post("/system/tenant/pagelist",para) //$.Post(.....)
                    .then(result=>{
                        this.total = result.data.total;
                        this.tenants = result.data.rows;
                        this.listLoading = false;  //关闭加载圈
                    });
				/* 查询所有
				this.$http.patch("/department",para) //$.Post(.....)
					.then(result=>{
                        console.log(result);
                        console.log(result.data);
                        this.tenants = result.data;
                        this.listLoading = false;  //关闭加载圈
                    });
                    */
			}
		},
		mounted() {
		    this.getTenants()
		}
	}

</script>

<style scoped>

</style>